// src/api/exchangeRateService.ts
import createAxios from '../utils/axios';

interface ExchangeRate {
  [currency: string]: number;
}

class ExchangeRateService {
  private apiUrl = 'v4/latest/USD'; // 示例API URL
  private rates: ExchangeRate = {};

  async fetchRates(): Promise<void> {
    try {
      const response = await createAxios({
        url: this.apiUrl,
        method: 'GET',
      }, 'API1', { loading: true });
      this.rates = response.data.rates;
    } catch (error) {
      console.error('Error fetching exchange rates:', error);
    }
  }

  getRate(currency: string): number {
    return this.rates[currency] || 1;
  }
}

export default new ExchangeRateService();